//
//  STGuidanceCollectionViewCell.swift
//  SeaTransportManage
//
//  Created by guopengwen on 2021/11/27.
//

import UIKit

class STGuidanceCollectionViewCell: UICollectionViewCell {
    
    class var identifier: String {
        get {
            return "STGuidanceCollectionViewCell"
        }
    }
    
    class func registerTo(_ collectionView: UICollectionView) {
        collectionView.register(STGuidanceCollectionViewCell.classForCoder(), forCellWithReuseIdentifier: STGuidanceCollectionViewCell.identifier)
    }
    
    class func reusableCell(_ collectionView: UICollectionView, indexPath: IndexPath) -> STGuidanceCollectionViewCell? {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: STGuidanceCollectionViewCell.identifier, for: indexPath) as? STGuidanceCollectionViewCell
        return cell
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor.white
        layer.cornerRadius = 12
        
        addSubview(iconView)
        iconView.snp.makeConstraints { (make) in
            make.top.equalTo(24)
            make.centerX.equalTo(self)
            make.width.equalTo(82)
            make.height.equalTo(82)
        }
        
        addSubview(descLabel)
        descLabel.snp.makeConstraints { (make) in
            make.top.equalTo(iconView.snp.bottom).offset(22)
            make.centerX.equalTo(self)
            make.left.equalTo(0)
            make.right.equalTo(0)
        }
        
        let imgView = UIImageView.init(image: UIImage.init(named: "icon_go"))
        addSubview(imgView)
        imgView.snp.makeConstraints { (make) in
            make.top.equalTo(descLabel.snp.bottom).offset(10)
            make.centerX.equalTo(self)
            make.width.equalTo(32)
            make.height.equalTo(32)
        }
    
    }
    
    public func updateCellData(boxType: Int) {
        let iconName = self.getBoxIconName(boxType)
        let desc = self.getBoxDesc(boxType)
        iconView.image = UIImage.init(named: iconName)
        descLabel.text = desc
    }
    
    func getBoxIconName (_ boxType: Int) -> String {
        switch boxType {
            case 0:
                return "icon_rugang"
            case 1:
                return "icon_tixiang"
            case 2:
                return "icon_zhuangxiang"
            case 3:
                return "icon_kefu"
            default: return "icon_rugang"
        }
    }
    
    func getBoxDesc (_ boxType: Int) -> String {
        switch boxType {
            case 0:
                return "入港流程指引"
            case 1:
                return "提空箱拍照指引"
            case 2:
                return "装箱拍照指引"
            case 3:
                return "联系客服"
            default: return ""
        }
    }
    
    lazy var iconView: UIImageView = {
        let imgView = UIImageView.init()
        return imgView
    }()
    
    
    lazy var descLabel: UILabel = {
        let lb = UILabel.init()
        lb.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.heavy)
        lb.textAlignment = .center
        return lb
    }()
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
